<?php

//
session_start();
//
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {

    header("Location: login.php");
}
//
include 'i_functions.php';
//
$_SESSION['Trace'] = "";
$Trace = $_SESSION['Trace'];
//
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $FormID = $_GET['Form'];
    if (!$FormID) {
        $FormID = "You need to give me a form ID to start!";
    }
    $FormTitle = $_GET['Title'];
    if (!$FormTitle) {
        $FormTitle = $FormID;
    }
    $TableName = $_GET['Table'];
    $Filter = $_GET['Filter'];
    if ($Filter <> "") {
        $tmp_Filter = explode(":", $Filter);
        $Filter = $tmp_Filter[0] . " LIKE '%" . $tmp_Filter[1] . "%'";
    }
    $OrderBy = $_GET['OrderBy'];
    $DataType = $_GET['DataType'];
    $_SESSION['DataType'] = $DataType;
//
    $user_name = "root";
    $pass_word = "haddons";
    $database = "PPI";
    $server = "127.0.0.1";
//
    $db_handle = mysql_connect($server, $user_name, $pass_word);
    $db_found = mysql_select_db($database, $db_handle);
    if ($Trace) {
        print "<br>FormSearch.php - db_handle = ";
        var_dump($db_handle);
        print "<br>db_found = " . $db_found;
    }
    //
    $_SESSION['Work'] = array();
    //$csvFile = $FormID . ".txt";
    $Columns = array();
    $Options = array();
    $Options['Name'] = "Form";
    $Options['TableOpts'] = "Align=\"center\"";
    $Options['Action'] = "./Form.php?Form=" . $FormID . "&Title=" . $FormTitle . "&Table=" . $TableName . "&ID=";
    $Options['AllowNew'] = "Y";
    $Options['Filter'] = $Filter;
    $Options['OrderBy'] = $OrderBy;
    $Options['DataType'] = $DataType;
    //$Options['Trace'] = "Y";
    $Result = BuildDataArray($TableName, $FormID, $Columns, $Options);
    $HTML_F = Array2Table($xData, $Columns, $Options);
//    
    include 'i_head.php';
    print $HTML_F;
    include 'i_foot.html';
}
?>
